package com.itheima.controller;

import com.itheima.domain.mongo.Advice;
import com.itheima.domain.vo.PageBeanVo;
import com.itheima.manager.AdviceManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class AdviceController {

    @Autowired
    private AdviceManager adviceManager;

    //分页查询所有反馈信息
    @GetMapping("/adviceByPage")
    public PageBeanVo adviceByPage(
            @RequestParam(defaultValue = "1") Integer pageNum ,
            @RequestParam(defaultValue = "5") Integer pageSize
    ){
        return adviceManager.findAdviceList(pageNum, pageSize);
    }


    //保存反馈
    @PostMapping("/saveAdvice")
    public String saveAdvice(@RequestBody Advice advice) {

        adviceManager.saveAdvice(advice);
        return "ok";
    }


    //删除反馈
    @PostMapping("/deleteAdvice")
    public String deleteAdvice(@RequestBody Advice advice) {

        Long userId = advice.getUserId();
        adviceManager.deleteAdvice(userId);
        return "ok";
    }


    //回显反馈
    @PostMapping("/showAdvice")
    public Advice showAdvice(@RequestBody Advice advice) {

        return advice;
    }
}
